﻿using EntityPet;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PET.Tools;
using Tools;

namespace PET.Controllers
{
    /// <summary>
    /// 生产——财务控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FinanceController : ControllerBase
    {
        private readonly PetDbContext petC;
        public FinanceController(PetDbContext db)
        {
            petC = db;
        }

        //[HttpGet]
        //public Result Get()
        //{
        //    Result result = new Result();
        //    result.Data = petC.Pet_finance.ToList();
        //    return result;
        //}

        [HttpGet("GetA")]
        public List<Pet_finance> GetAll()
        {
            return petC.Pet_finance.ToList();
        }
        

        [HttpGet("id")]
        public Result GetId(Guid id)
        {
            Result result = new Result();
            result.Data = petC.Pet_finance.Where(w => w.FiId == id).SingleOrDefault();
            return result;
        }


        [HttpDelete]
        public Result Del(Guid id)
        {
            Result result = new Result();
            Pet_finance? cai = petC.Pet_finance.Where(w => w.FiId == id).SingleOrDefault();
            if (cai != null)
                petC.Pet_finance.Remove(cai);
            result.Data = petC.SaveChanges();
            return result;
        }


        [HttpPost]
        public Result AddPet([FromBody] Pet_finance finance)
        {
            Result result = new Result();
            petC.Pet_finance.Add(finance);
            result.Data = petC.SaveChanges();
            return result;
        }

        [HttpPut]
        public Result Put([FromBody] Pet_finance finance)
        {
            Result result = new Result();
            petC.Pet_finance.Update(finance);
            result.Data = petC.SaveChanges();
            return result;
        }

        //[HttpGet("like{Time}")]
        //public List<Pet_finance> Getfin(DateTime Time)
        //{
        //    List<Pet_finance> fin = new List<Pet_finance>();

        //    DateTime nowB = new DateTime(2020,2,12);
        //    DateTime nowL = new DateTime(2020,12,12);
        //    fin.Where(w => w.Time > nowB&&w.Time< nowL);
            

        //}

    }
}
